# -*- coding: utf-8 -*-
from datetime import timedelta

from jms.dwd.dwd_warhouse.dwd_wide_rank_basic_scaninfo_dt import jms_dwd__dwd_wide_rank_basic_scaninfo_dt
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from jms.dwd.dwd_order_source_detail_dt import jms_dwd__dwd_order_source_detail_dt
from jms.dim.dim_lmdm_sys_network_expand import jms_dim__dim_lmdm_sys_network_expand


jms_dm__dm_agent_taking_arrival_agg_dt = SparkSqlOperator(
    task_id='jms_dm__dm_agent_taking_arrival_agg_dt',
    email=['houwenlong@jtexpress.com','yl_bigdata@yl-scm.com'],
    task_concurrency=1,
    pool_slots=6,
    master='yarn',
    # sla=timedelta(hours=7),
    name='jms_dm__dm_agent_taking_arrival_agg_dt_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/dm/dm_agent_taking_arrival_agg_dt/execute.hql',
    driver_memory='16G',
    driver_cores=4,
    executor_cores=4,
    executor_memory='12G',
    num_executors=10,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={
        'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
        'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
        'spark.dynamicAllocation.maxExecutors': 100,  # 动态资源最大扩容 Executor 数
        'spark.dynamicAllocation.cachedExecutorIdleTimeout': 120,  # 动态资源自动释放闲置 Executor 的超时时间(s)
        'spark.executor.memoryOverhead': '2G',  # 堆外内存
        'spark.hadoop.hive.exec.dynamic.partition.mode': 'nonstrict',
        'spark.hadoop.hive.exec.dynamic.partition': 'true'
    },
    yarn_queue='pro',
    #execution_timeout=timedelta(hours=3)
    #excel平均时长:3分1秒
    execution_timeout = timedelta(minutes=15),
)

jms_dm__dm_agent_taking_arrival_agg_dt << [
    jms_dwd__dwd_wide_rank_basic_scaninfo_dt,
    jms_dim__dim_lmdm_sys_network_expand,
    jms_dwd__dwd_order_source_detail_dt,
]
